package com.whoimi.common;

import org.slf4j.helpers.MessageFormatter;

/**
 * @author whoimi
 * @since 2023-12-29
 **/
public class NotifyException extends RuntimeException {
    private Integer errorCode = ResultInfo.Constant.CODE_FAIL;
    private String errorMessage;

    public NotifyException(String errorMessage) {
        super(errorMessage);
        this.errorMessage = errorMessage;
    }

    public NotifyException(String errorMessage, Object... args) {
        super(MessageFormatter.arrayFormat(errorMessage, args).getMessage());
        this.errorMessage = MessageFormatter.arrayFormat(errorMessage, args).getMessage();
    }

    public NotifyException(Integer errorCode, String errorMessage) {
        super(errorMessage);
        this.errorCode = errorCode;
        this.errorMessage = errorMessage;
    }

    public NotifyException(Integer errorCode, String errorMessage, Object... args) {
        super(MessageFormatter.arrayFormat(errorMessage, args).getMessage());
        this.errorCode = errorCode;
        this.errorMessage = MessageFormatter.arrayFormat(errorMessage, args).getMessage();
    }

    public NotifyException(ResultInfo.ResultEnum resultEnum) {
        this(resultEnum.getResultCode(), resultEnum.getResultMsg());
    }

    public NotifyException(ResultInfo.ResultEnum resultEnum, Object... args) {
        this(resultEnum.getResultCode(), resultEnum.getResultMsg(), args);
    }

    public Integer getErrorCode() {
        return errorCode;
    }

    public void setErrorCode(Integer errorCode) {
        this.errorCode = errorCode;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public void setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
    }
}
